<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="admin.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%! static int PAGE_SIZE = 10; %>
<%
	String pageNum = request.getParameter("page");//페이지를 누를때 불러온다.
	if(pageNum == null) pageNum = "1";//페이지값이 없으면 1로 설정
	int currentPage = Integer.parseInt(pageNum);//현재페이지를 페이지값으로 설정
	MemberWritingManager manager = MemberWritingManager.getInstance();
	int count = manager.count();//건수를 불러온다.
	int totalPageCount = 0;
	int startRow = 0, endRow = 0;
	if(count > 0){
		totalPageCount = count / PAGE_SIZE;
		if(count % PAGE_SIZE > 0) totalPageCount++;
		startRow = (currentPage - 1) * PAGE_SIZE + 1;//페이징 처리구문
		endRow = currentPage * PAGE_SIZE;
	}
	List list = manager.selectList(startRow, endRow);
%>

<%@ include file="/Dmyna/admin/head.jsp" %>
<c:set var="list" value="<%= list %>" />
<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;" align="center">
					::&nbsp;&nbsp;회원 관리&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>
<table width="900" align="center" cellpadding="0" cellspacing="0">
<tr>
	<td>
    <table align="center" cellspacing="0" cellpadding="0" class="board_list">
    <col width="50" />
    <col width="110" />
    <col width="110" />
    <col width="110" />
    <col width="110" />

	<tr>
        <th>회원번호</th>
        <th>아이디</th>
        <th>이름</th>
        <th>연락처</th>
        <th>가입일</th>
    </tr>

	<c:if test="${empty list }">
		<tr>
			<td bgcolor="#f0f0f0" colspan="5" align="center" >
			등록된 회원이 없습니다.
			</td>
		</tr>
	</c:if>
	<c:if test="${!empty list }">
		<c:forEach var="writing" items="${list }">
			<tr bgcolor="#f0f0f0">
			<c:set var="bgChk" value="${ (cnt % 2) == 0 ? 0 : 1 }" />
				<tr class="bg${bgChk }">
				<td class="num"><a href="javascript:goView(${writing.mb_no })">${writing.mb_no }</a></td>
				<td class="name"><a href="javascript:goView(${writing.mb_no })">${writing.mb_id }</a></td>
				<td class="name"><a href="javascript:goView(${writing.mb_no })">${writing.mb_name }</a></td>
				<td class="num">${writing.mb_phone }</td>
				<td class="datetime">${writing.mb_date }</td>
			</tr>
		</c:forEach>
	</c:if>
					<tr>
					<td colspan='5' height=25 align=center>
						<div class="board_page">

							<!--페이지 번호 시작-->
							<c:set var="count" value="<%=Integer.toString(count)%>" />
							<c:set var="PAGE_SIZE" value="<%=Integer.toString(PAGE_SIZE)%>" />
							<c:set var="currentPage"
								value="<%=Integer.toString(currentPage)%>" />
							<c:if test="${count > 0 }">

								<c:set var="pageCount"
									value="${count / PAGE_SIZE + (count % PAGE_SIZE == 0 ? 0 : 1) }" />
								<c:set var="startPage"
									value="${currentPage - (currentPage % 10 == 0 ? 10:(currentPage % 10)) + 1 }" />
								<c:set var="endPage" value="${startPage + 9 }" />
								<c:if test="${endPage > pageCount }">
									<c:set var="endPage" value="${pageCount }" />
								</c:if>
								
								<!-- 처음버튼 -->
								<c:if test="${startPage > 1  }">
									<a href="javascript:goPage(${startPage})"> <img
										src='${WEB_ROOT }/img/bbs/page_begin.gif' border='0'
										align='absmiddle' title='처음'>&nbsp;
									</a>
								</c:if>
								
								<!-- 이전버튼 -->
								<c:if test="${startPage > 10  }">
									<a href="javascript:goPage(${startPage-10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_prev.gif' border='0'
										align='absmiddle' title='이전'>&nbsp;
									</a>
								</c:if>

								<!-- 숫자표시 -->
								<c:forEach var="pageNo" begin="${startPage }" end="${endPage }">
									<c:if test="${currentPage == pageNo }">
										<font size="4">
									</c:if>
									<a href="javascript:goPage(${pageNo })">${pageNo }&nbsp;</a>
									<c:if test="${currentPage == pageNo }">
										</font>
									</c:if>
								</c:forEach>

								<!-- 다음버튼 -->
								<c:if test="${endPage < pageCount  }">
									<a href="javascript:goPage(${startPage+10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_next.gif' border='0'
										align='absmiddle' title='다음'>&nbsp;
									</a>
								</c:if>

								<!-- 맨끝버튼 -->
								<c:if test="${startPage > 1  }">
									<a href="javascript:goPage(<fmt:formatNumber value="${endPage}" pattern="#"/>)"> <img
										src='${WEB_ROOT }/img/bbs/page_end.gif' border='0'
										align='absmiddle' title='맨끝'></a>
								</c:if>
							</c:if>
							<!--페이지 번호 종료-->

						</div>
					</td>
				</tr>
				<tr>
					<!-- 전체게시물수 표시 -->
					<td colspan="5" height=25 align="left"><%=count%> 명의 회원이 가입하셨습니다.</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

<%@ include file="/Dmyna/admin/tail.jsp" %>

<script language="JavaScript">
function goPage(pageNo){
	document.move.action = "/Dmyna/admin/member/memberList.jsp";
	document.move.page.value = pageNo;
	document.move.submit();
}
function goView(mb_no){
	document.move.action = "/Dmyna/admin/member/memberForm.jsp";
	document.move.mb_no.value = mb_no;
	document.move.submit();
}
</script>
<form name="move" method="post" >
<input type="hidden" name="mb_no" value="" />
<input type="hidden" name="page" value="${currentPage }" />
</form>
